package db

import (
	"commonUtils/config"

	_ "github.com/go-sql-driver/mysql" //不能忘记导入
	xorm "xorm.io/xorm"
)

// NewMySQLEngine 初始化数据库连接
func NewMySQLEngine(conf *config.DBConfig) *xorm.Engine {
	engine, err := xorm.NewEngine(conf.Drive, conf.User+":"+conf.Pass+"@"+conf.Addr+":"+conf.Port+"/"+conf.DBName+"?charset="+conf.Charset)
	if err != nil {
		panic(err.Error())
	}

	//设置显示sql语句
	// if config.IsDebug() {
	// 	engine.ShowSQL(true)
	// }
	engine.SetMaxOpenConns(10)

	return engine
}
